package top.usts.springframework.beans.factory.config;

import top.usts.springframework.beans.BeansException;
import top.usts.springframework.beans.PropertyValues;

/**
 * @description:
 * @author: CJ
 * @date: 2022/2/25
 */
public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor{


    /**
     * 在bean执行初始化方法之前 执行此方法
     * @param beanClass
     * @param beanName
     * @return
     * @throws BeansException
     */
    Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException;

    /**
     * 在bean执行初始化方法之后 执行此方法
     * @param bean
     * @param beanName
     * @return
     * @throws BeansException
     */
    boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException;


    /**
     * 在 Spring 中由 SmartInstantiationAwareBeanPostProcessor#getEarlyBeanReference 提供
     * @param pvs
     * @param bean
     * @param beanName
     * @return
     * @throws BeansException
     */
    PropertyValues postProcessPropertyValues(PropertyValues pvs, Object bean, String beanName) throws BeansException;

    default Object getEarlyBeanReference(Object bean, String beanName) {
        return bean;
    }
}
